<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class ChangeRelationTypeInNoteEntityRelationTable extends AbstractMigration
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change(): void
    {
        $table = $this->table('note_entity_relation');
        if (!($table->hasColumn('step_category_id'))) {
            $table = $table->addColumn('step_category_id', 'integer', ['limit' => 11, 'default' => 0, 'null' => false, 'comment' => '工序分类id']);
        }
        if (!($table->hasColumn('step_id'))) {
            $table = $table->addColumn('step_id', 'integer', ['limit' => 11, 'default' => 0, 'null' => false, 'comment' => '工序id']);
        }
        $table = $table
            ->addColumn('review_feedback_id', 'integer', ['limit' => 11, 'default' => 0, 'null' => false, 'comment' => '审核反馈id'])
            ->changeColumn('relation_type', 'string', ['null' => false, 'default' => '', 'limit' => 20, 'comment' => '关联类型(episode 集,entity 实体,step_category 工序分类,step 工序)'])
            ->addIndex(['review_feedback_id', 'relate_module_code'], ['type' => 'normal', 'name' => 'idx_review_feedback_id_relate_module_code'])
            ->addIndex(['entity_id'], ['type' => 'normal', 'name' => 'idx_entity_id']);

        $table->save();
    }
}
